class Editconfig {
    constructor($modalInstance, $scope, item, imageSrv, $stateParams) {
        "ngInject"
        if (item) {
            if (item.isVer == 1) {
                $scope.title = "添加配置版本";
                $scope.confignameDia = true;
                $scope.formDatas = {
                    configName: item.configName,
                    configVersion: '',
                    config: [{ key: '', value: '', remark: '' }]
                }
            } else {
                $scope.title = "修改配置文件";
                $scope.formDatas = {
                    id: item.id,
                    configName: item.configName,
                    configVersion: item.configVersion,
                    config: item.config
                }
            }

        } else {
            $scope.title = "添加配置文件";
            $scope.formDatas = {
                configName: '',
                configVersion: '',
                config: [{ key: '', value: '', remark: '' }]
            }
        }

        $scope.ok = () => {
            $modalInstance.close($scope.formDatas);
        }
        $scope.cancel = () => {
            $modalInstance.dismiss();
        }
        $scope.addRow = () => {
            $scope.formDatas.config.push({ key: '', value: '', remark: '' });
        }
        $scope.deleteRow = (index) => {
            $scope.formDatas.config.splice(index, 1);
        }
        $scope.checkVer = () => {
            $scope.verLoading = true;
            imageSrv.checkVersion({ dockerImageTagId: $stateParams.id, configVersion: $scope.formDatas.configVersion,config_name:$scope.formDatas.configName }).then((data) => {
                
                    $scope.hasVer = !data;
                
            }).catch(() => {

            }).finally(() => {
                $scope.verLoading = false;
            })
        }
    }
}

export default Editconfig;